#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

const int N=300;
const int INF=0x3f3f3f3f;
int edge[N][N];
int vis[N];

int main()
{
	int n,m;
	cin>>n>>m;
	memset(edge,INF,sizeof(edge));
	for(int i=0;i<m;i++)
	{
		int x,y,z;
		cin>>x>>y>>z;	
		edge[x][y]=edge[y][x]=z;
		
	}
	
	int k;
	cin>>k;
	int retPos,retSum=INF;
	int ret=0;
	for(int j=1;j<=k;j++)
	{
		int cnt=0,sum=0;
		int p;
		cin>>p;
		vector<int> path;
		for(int i=0;i<p;i++)
		{
			int t;
			cin>>t;
			path.push_back(t);
		}
		if(p!=n || edge[0][path[p-1]]==INF || edge[0][path[0]]==INF)
			continue;
//		cout<<edge[0][path[p-1]]<<' '<<INF<<endl;
//cout<<"+++"<<endl;
		int cur=0;
		memset(vis,0,sizeof(vis));
		for(int i=0;i<p;i++)
		{
			int t=path[i];
			if(!vis[t] &&edge[cur][t]!=INF)
			{
				vis[t]=1;
				cnt++;
				sum+=edge[cur][t];
				cur=t;
			}
		}
	
		sum+=edge[cur][0];
		if(cnt==n)
		{
//			cout<<j<<' '<<edge[cur][0]<<endl;
			ret++;
			if(sum<retSum)
			{
				retSum=sum;
				retPos=j;
			}
		}		
	}
	cout<<ret<<endl;
	cout<<retPos<<' '<<retSum<<endl;
	
	return 0;
}
